const { defineConfig } = require('@vue/cli-service')
const CompressionWebpackPlugin = require('compression-webpack-plugin');
require('events').EventEmitter.defaultMaxListeners = 20; // 解除限制

module.exports = defineConfig({
    transpileDependencies: true,
    configureWebpack: {
        plugins: [
            new CompressionWebpackPlugin({
                test: /\.js$|\.html$|\.css/,
                threshold: 20480,
                deleteOriginalAssets: false
            }),
        ],
    },
    devServer: {
        client: {
            overlay: {
                errors: true,
                warnings: false,
                runtimeErrors: true,
            },
        },
        historyApiFallback: true, // 处理刷新时的 404 错误
        proxy: {
            "/su": {
                target: 'http://suggestion.baidu.com',
                changeOrigin: true,
                pathRewrite: {'^/su': '/su'},
            },
            "/v2": {
                target: "https://geoapi.qweather.com",
                changeOrigin: true,
                pathRewrite: {'^/v2': '/v2'},
            },
            "/v7": {
                target: "https://devapi.qweather.com",
                changeOrigin: true,
                pathRewrite: {'^/v7': '/v7'},
            },
            "/tft": {
                target: 'http://139.224.51.76:30000',
                changeOrigin: true,
                pathRewrite: {'^/tft': '/tft'},
            },
            "/lachesism": {
                target: 'http://139.224.51.76:30000',
                changeOrigin: true,
                pathRewrite: {'^/lachesism': '/lachesism'},
            },
            "/lachesismManage": {
                target: 'http://139.224.51.76:30000',
                changeOrigin: true,
                pathRewrite: {'^/lachesismManage': '/lachesismManage'},
            },
            "/wmj": {
                target: 'http://139.224.51.76:30000',
                changeOrigin: true,
                pathRewrite: {'^/wmj': '/wmj'},
            },
            "/pub": {
                target: 'http://139.224.51.76:30000',
                changeOrigin: true,
                pathRewrite: {'^/pub': '/pub'},
            },
            "/secret": {
                target: 'http://yuno-oss.oss-cn-shanghai.aliyuncs.com',
                changeOrigin: true,
                pathRewrite: {'^/secret': '/secret'},
            },
        },
    }
})
